package com.neusoft.movie.v_movies.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.neusoft.movie.v_movies.R;
import com.neusoft.movie.v_movies.common.Constants;
import com.neusoft.movie.v_movies.javabean.ActivityBean;
import com.neusoft.movie.v_movies.listener.RetrofitListener;
import com.neusoft.movie.v_movies.model.ActivityModel;
import com.squareup.picasso.Picasso;

import static com.neusoft.movie.v_movies.common.Constants.PHOTO_URL;

public class ActInfoActivity extends BaseActivity implements RetrofitListener {

    private TextView act_name,act_time,act_info,act_way;
    private ImageView act_pic,left;
    private Button button_enter;
    private int act_id;
    private Context mContext;
    private int u_id;

    @Override
    void initViews() {
        setLayout(R.layout.activity_act_info);
        act_name = (TextView) findViewById(R.id.act_name);
        act_pic = (ImageView) findViewById(R.id.act_pic);
        act_time = (TextView) findViewById(R.id.act_time);
        act_info = (TextView) findViewById(R.id.act_info);
        act_way = (TextView) findViewById(R.id.act_way);
        button_enter= (Button) findViewById(R.id.button_enter);
        left=(ImageView) findViewById(R.id.left_button);

    }

    @Override
    void initData() {
        act_id=getIntent().getIntExtra("act_id",-1);
        getDetail();

    }
    void getDetail()
    {
        ActivityModel activityModel = new ActivityModel();
        activityModel.getDetail(act_id,this);
    }




    @Override
    void initEvents() {
        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


        button_enter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(ActInfoActivity.this, EnterActActivity.class);
                Bundle bundle = new Bundle();
                bundle.putInt("act_id",act_id);
                intent.putExtras(bundle);
                startActivityForResult(intent, 1);

            }
        });

    }

    @Override
    public void onSuccess(Object o, int flag) {
        switch(flag){
            case Constants.GETACTIVITYDETAIL:
                ActivityBean activityBean=(ActivityBean) o;
                String pic = PHOTO_URL+activityBean.getAct_pic();
                if(!activityBean.getAct_pic().equals("")){
                    Picasso.with(mContext).load(pic).into(act_pic);
                }
                act_name.setText(activityBean.getAct_name());
                act_info.setText(activityBean.getAct_info());
                act_way.setText(activityBean.getAct_way());
                act_time.setText(activityBean.getAa_time());
                break;
        }
    }

    @Override
    public void onFailed() {

    }
}
